package com.CST.controller.cb;

import com.CST.common.api.ResultObject;
import com.CST.dto.cb.SysRoleDTO;
import com.CST.entity.cb.BdSysRole;
import com.CST.service.cb.IBdSysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色管理
 * </p>
 *
 * @author y
 * @since 2021-09-27
 */
@Api(tags = {"角色管理"})
@RestController
@RequestMapping("/bdSysRole")
public class BdSysRoleController {

    @Autowired
    private IBdSysRoleService iBdSysRoleService;

    /**
     * <p>插入新角色表</p >
     *
     * @return com.CST.common.api.ResultObject
     *
     * @author y
     * @since 2021/09/27 09:20
     */
    @ApiOperation("插入新角色")
    @PostMapping("/insertRole")
    public ResultObject insertRole(@RequestBody BdSysRole bdSysRole) {
        return ResultObject.success(iBdSysRoleService.insertSysRole(bdSysRole));
    }

    /**
     * <p>删除角色</p >
     *
     * @return com.CST.common.api.ResultObject
     *
     * @author y
     * @since 2021/09/27 09:22
     */
    @ApiOperation("删除角色")
    @DeleteMapping("/deleteRole")
    public ResultObject deleteRole(@RequestParam String id) {
        if (iBdSysRoleService.deleteSysRoleById(id)) {
            return ResultObject.successReturn("删除成功");
        } else {
            return ResultObject.errorReturn("删除账户失败");
        }
    }

    /**
     * <p>通过id更新角色表</p >
     *
     * @return boolean
     *
     * @author y
     * @since 2021/09/27 09:11
     */
    @ApiOperation("修改角色")
    @PostMapping("/updateRole")
    public ResultObject updateSysRole(@RequestBody BdSysRole bdSysRole) {
        return iBdSysRoleService.updateSysRole(bdSysRole) ? ResultObject.successReturn("修改角色成功") : ResultObject.errorReturn("修改角色失败");
    }

    /**
     * <p>查询角色表</p >
     *
     * @return com.CST.entity.cb.BdSysRole
     *
     * @author y
     * @since 2021/09/27 09:13
     */
    @ApiOperation("id查询详情")
    @GetMapping("/getSysRoleById")
    public ResultObject getSysRoleById(@RequestParam String id) {
        return ResultObject.successReturn(iBdSysRoleService.getSysRoleById(id));
    }

    /**
     * <p>id和名称查询查询角色表</p >
     *
     * @return com.CST.entity.cb.BdSysRole
     *
     * @author y
     * @since 2021/09/27 09:13
     */
    @ApiOperation("根据用户名或ID查询")
    @GetMapping("/getSysRole")
    public ResultObject getSysRole(@RequestParam("id") String id, @RequestParam("roleName") String roleName) {
        return ResultObject.successReturn(iBdSysRoleService.getSysRole(id, roleName));
    }

    /**
     * <p>列表查询</p >
     *
     * @return java.util.List<com.CST.entity.cb.BdSysRole>
     *
     * @author y
     * @since 2021/09/27 09:16
     */
    @ApiOperation("列表查询")
    @PostMapping("/getSysRoles")
    public ResultObject getSysRolesList(@RequestBody SysRoleDTO sysRoleDto) {
        return ResultObject.successReturn(iBdSysRoleService.getSysRolesList(sysRoleDto));
    }

    /**
     * <p>列表查询</p >
     *
     * @return java.util.List<com.CST.entity.cb.BdSysRole>
     *
     */
    @ApiOperation("列表查询")
    @GetMapping("/getSysRolesAll")
    public ResultObject getSysRolesListAll() {
        return ResultObject.successReturn(iBdSysRoleService.getSysRolesListAll());
    }

}

